package com.zhaopin.tocompanyproject;

import com.alibaba.fastjson.JSONObject;
import com.zhaopin.utils.DateUtils;
import com.zhaopin.utils.HttpUtils;

/**
 * @author Administrator
 * @create 2019-06-17 15:22
 */
public class GetToEsData {


    public static void main(String[] args) {

        String url = "http://api.open.zhaopin.com/platform/org/get?access_token=551c619ef13c45debe92a64880f5e1cdlzJv&orgid=";
//        String orgId = "300021911";
//        String orgId = "82343642";
//        String orgId = "56040858";
//        String orgId = "31985858";
//        String orgId = "81982914";
//        String orgId = "68728963";
//        String orgId = "33224418";
//        String orgId = "85034728";
//        String orgId = "86968363";
//        String orgId = "13856774";
        String orgId = "83280337";

        String canUrl = url + orgId;

        String returnStr = HttpUtils.get(canUrl, 5000);
        JSONObject jsonObject = JSONObject.parseObject(returnStr);
        //首先获取 sourceid
        JSONObject data = jsonObject.getJSONObject("data");
        Integer sourceid = data.getInteger("sourceid");
        String id = "";
        String orgnumber = data.getString("orgnumber");
        String orgnumber2 = data.getString("orgnumbe2");
        if (sourceid % 2 == 1) {
            id = orgnumber;
        } else {
            id = orgnumber2;
        }

        String number = orgId;
        String name = data.getString("companyname");
        String createTime = DateUtils.getTimestampToFormatedTime(data.getString("createTime"), DateUtils.yyyyMMddTHHmmssZ);
        JSONObject jsonObject1 = new JSONObject();
        if(null == id || "".equals(id)){
            id = orgnumber == null ? orgnumber2 : orgnumber;
        }
        jsonObject1.put("id", id);
        jsonObject1.put("number", number);
        jsonObject1.put("name", name);
        jsonObject1.put("createTime", createTime);
        System.out.println("es 的 _id为： " + id);
        System.out.println(jsonObject1.toJSONString());

    }
}
